package com.andox.fn.inf.rpc.rest.filter;

import java.util.List;

import com.andox.fn.inf.rpc.rest.RpcRequest;
import com.andox.fn.inf.rpc.rest.RpcResponse;
import com.andox.fn.inf.rpc.rest.config.InterfaceConfig;

/**   
 * @ClassName:   FilterUtil   
 * @Description: TODO  
 * @author:      Andox
 * @date:        2019年8月2日 下午6:16:58   
 *     
 */
public class FilterUtil {
	public static Invoker buildFilter(Invoker invoker, List<Filter> filters) {
		Invoker last = invoker;
		for (Filter filter : filters) {
			Invoker next = last;
			last = new Invoker() {
				@Override
				public RpcResponse invoke(RpcRequest request) {
					return filter.invoke(next, request);
				}

				@Override
				public InterfaceConfig getConfig() {
					return invoker.getConfig();
				}
			};
		}
		
		return last;
	}
}
